package logic

import (
	"context"
	"exam/docker/mysql"
	"exam/exzmrpc/exzmrpc"
	"exam/exzmrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *exzmrpc.ListRequest) (*exzmrpc.ListResponse, error) {
	// todo: add your logic here and delete this line
	var user []mysql.User

	mysql.DB.Debug().Find(&user)
	var deme []*exzmrpc.List

	for _, i2 := range user {
		list := exzmrpc.List{
			UserId: int64(i2.ID),
			Title:  i2.Title,
			Number: int64(i2.Number),
			Types:  int64(i2.Types),
		}
		deme = append(deme, &list)
	}

	return &exzmrpc.ListResponse{
		List: deme,
	}, nil
}
